using IQIGame.Onigao.Game;
using IQIGame.Onigao.Logic;

namespace IQIGame.Onigao.GamePlay
{
    public class CFSMState_Level_Logic_Monster_ReturnToPost : CFSMState<IQIGame.Onigao.Logic.LevelEntity, CFSMLevel_Logic_MonsterData>
    {
        private LgEntityReturnToPostComponent _returnPostCom;
        public override void OnInit()
        {

        }

        public override void OnEnter(int prevStateId)
        {
            _returnPostCom = entity.AddComponent<LgEntityReturnToPostComponent>();
            _returnPostCom.Start(data.chaseStartPos);
            if (data.alertValue != 0)
            {
                data.alertValue = 0;
                if (data.lockingEntity != null)
                {
                    entity.ChangeAlertEnemy(data.lockingEntity, 0);
                }
            }
            data.lockingEntity = null;
        }

        public override void OnUpdate(float deltaTime)
        {
            data.isReturningToPost = _returnPostCom.isRunning;
        }

        public override void OnExit()
        {
            entity.RemoveComponent<LgEntityReturnToPostComponent>();
            _returnPostCom = null;

            data.isOutOfPost = false;
            data.chaseStartPos = default;
        }

        public override void OnReset()
        {
            _returnPostCom = null;
            base.OnReset();
        }
    }
}
